﻿using System.IO;
using System.Xml.Serialization;

namespace ThinkDotNetEditorLib.Models.StaticObjects
{
    public class StaticObjectInfoLoader : IStaticObjectInfoLoader
    {        
        public StaticObjectInfo[] Load(string path)
        {
            StaticObjectInfo[] staticObjectInfo;
            using (Stream stream = File.Open(path, FileMode.Open))
            {
                XmlSerializer serializer = new XmlSerializer(typeof (StaticObjectInfo[]));
                staticObjectInfo = (StaticObjectInfo[])serializer.Deserialize(stream);                
            }
            return staticObjectInfo;
        }
        public void Save(string path, StaticObjectInfo[] staticObjectInfos)
        {
            using (Stream stream = File.Open(path, FileMode.OpenOrCreate))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(StaticObjectInfo[]));
                serializer.Serialize(stream, staticObjectInfos);
            }
        }
    }
}
